package com.jade.bss.customer.role;

import java.io.Serializable;
import java.security.Principal;
import java.util.Date;
import javax.persistence.*;

/**
 * 角色对象。角色代表了一组权限的集合，一个Principal如果为某一个角色，
 * 那么他将拥有这个角色所对应的权限。
 *
 * @author sky
 * @version 1.0 13-4-18 上午9:33
 */
@Entity
@Table (name = "BSS_CUSTOMER_ROLE")
public class RoleEntry  implements Serializable
{
    /** 角色id */
    @Id
    @GeneratedValue (generator = "BSS_SEQ_ROLE")
    @SequenceGenerator (name = "BSS_SEQ_ROLE", sequenceName = "BSS_SEQ_ROLE")
    private int id;
    //客户所有者标识
    @Column (name = "owner_id", nullable = false,updatable = false,length = 64)
    private String ownerId;
    /** 角色类型 */
    @Column (nullable = false, length = 16)
    private String type = "system";

    /** 角色名称 */
    @Column (nullable = false, length = 64)
    private String name;

    /** 角色描述 */
    @Column (length = 512)
    private String description;

    /** 角色状态 */
    @Column (nullable = false)
    private int status = 0;

    /** 创建时间 */
    @Column (name = "creation_date", nullable = false, updatable = false)
    private Date creationDate;

    @Transient
    private Principal principal;

    public String getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(String ownerId) {
        this.ownerId = ownerId;
    }

    public int getId()
    {
        return id;
    }

    public void setId(int id)
    {
        this.id = id;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public int getStatus()
    {
        return status;
    }

    public void setStatus(int status)
    {
        this.status = status;
    }

    public Date getCreationDate()
    {
        return creationDate;
    }

    public void setCreationDate(Date creationDate)
    {
        this.creationDate = creationDate;
    }

    public String getType()
    {
        return type;
    }

    public void setType(String type)
    {
        this.type = type;
    }

    //    public Principal getPrincipal()
    //    {
    //        if (principal == null && id > 0) {
    //            SimplePrincipal principal = new SimplePrincipal();
    //            principal.setType(SimplePrincipal.TYPE_ROLE);
    //            principal.setName(String.valueOf(id));
    //            this.principal = principal;
    //        }
    //        return principal;
    //    }
}